import { getAreaObj, regularRule } from '@/utils/util'
import apiMod from '@/apiMod/index'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '所属机构',
			prop: 'creditCode',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			rules: [{ required: true, message: '请输入当前所属机构' }],
			span: 12,
			change: (item, form, value) => {
				if (!item.creditCode) {
					return
				}
				form.organizationId = item.creditCode
				form.provinceId = item.provinceId
				form.provinceName = item.provinceName
				form.cityId = item.cityId
				form.cityName = item.cityName
				form.areaId = item.areaId
				form.areaName = item.areaName
				form.streetId = item.streetId
				form.streetName = item.streetName
				form.communityId = item.communityId
				form.communityName = item.communityName
			},
		},
		{
			label: '姓名',
			prop: 'idCard',
			propName: 'oldmanName',
			type: 'remoteSelect',
			api: 'view_dpServiceObject_page',
			filterKey: 'idCard',
			filterLabel: 'name',
			multiple: false,
			rules: [{ required: true, message: '请选择老人' }],
			span: 12,
			change: (item, form, value) => {
				form.phone = item.telephone
				form.idCard = item.idCard
			},
		},
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			disabled: true,
			span: 12,
			changeField: true,
			rules: [{ required: true, message: '请输入证件号码' }],
		},
		{
			label: '所属病区',
			prop: 'oldmanInpatient',
			type: 'input',
			span: 12,
			rules: [{ required: true, message: '请输入所属病区' }],
		},
		{
			label: '老人外出时间',
			prop: 'outTime',
			type: 'datetime',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			rules: [{ required: true, message: '请选择老人外出时间' }],
			span: 12,
		},
		{
			label: '预计返院时间',
			prop: 'returnTime',
			type: 'datetime',
			format: 'YYYY年MM月DD日 HH:mm:ss',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			rules: [{ required: true, message: '请选择预计返院时间' }],
			span: 12,
		},
		{
			label: '老人外出去向',
			prop: 'outReason',
			labelTip: '仅限直系亲属可带出病区',
			type: 'text',
			span: 12,
		},
		{
			label: '家属姓名',
			prop: 'familyName',
			type: 'text',
			span: 12,
		},
		{
			label: '家属联系电话',
			prop: 'familyPhone',
			type: 'text',
			span: 12,
		},
		{
			label: '家属与患者关系',
			prop: 'familyRelation',
			propName: 'familyRelationLabel',
			type: 'remoteSelect',
			code: 'ELDERLY_RELATIONSHIP',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			showLabel: false,
			span: 12,
		},
		{
			label: '家属签名照片',
			tip: '',
			prop: 'familySign',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
		{
			label: '申请状态',
			prop: 'auditStatus',
			type: 'select',
			dicData: [
				{ label: '申请中', value: '1' },
				{ label: '同意', value: '2' },
				{ label: '拒绝', value: '3' },
				{ label: '撤销申请', value: '4' },
			],
			span: 8,
			formDisplay: true,
			viewDisplay: true,
		},
		{
			label: '拒绝原因',
			prop: 'refuseReason',
			type: 'text',
			span: 12,
			formDisplay: true,
			viewDisplay: true,
		},
	],
}


export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '老人姓名', prop: 'oldmanName' },
		{ label: '身份证号', prop: 'idCard' },
		{ label: '老人外出时间', prop: 'outTime' },
		{ label: '预计返院时间', prop: 'returnTime' },
		{
			label: '家属姓名',
			prop: 'familyName',
		},
		{
			label: '申请状态',
			prop: 'auditStatus',
			custome: 'tag',
			dicData: [
				{ label: '申请中', value: '1', type: 'warning' },
				{ label: '同意', value: '2', type: 'success' },
				{ label: '拒绝', value: '3', type: 'danger' },
				{ label: '撤销申请', value: '4', type: 'info' },
			],
		},
		{ label: '签字照片', prop: 'familySign', custome: 'file' },
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbOldmanAppointment_page',
}
export const baseConfig = {
	pageName: '家属预约老人出院登记',
	dictcodes: ['ELDERLY_RELATIONSHIP'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'oldmanName',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		type: 1,
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,

	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
}
